<?php

use app\helpers\BookHelper;
use app\models\UserHistory;
use yii\helpers\Url;
use yii\web\View;

/* @var $this View */

$items = UserHistory::getHistory();
?>
<div class="popover-container">
    <div class="panel">
        <div class="panel-header d-flex">
            <h5>阅读历史</h5>
            <?php if(Yii::$app->user->isGuest): ?>
            <div class="col-ml-auto font-1"><a href="javascript:void(0);" class="mr-2 do-ajax-login hover">登录</a><em class="text-muted">后将能同步并永久保存记录</em>
            </div>
            <?php endif; ?>
        </div>
        <div class="panel-body">
            <?php if(!empty($items)): ?>
            <?php foreach ($items as $k => $item): ?>
                <div class="tile font-1" id="book-<?= $item['book_id']; ?>">
                    <div class="tile-icon mr-2 text-muted">
                        [<?= Yii::$app->formatter->asRelativeTime($item['create_time']); ?>]
                    </div>
                    <div class="tile-content-2 text-ellipsis">
                        <a class="text-normal hover" href="<?= Url::to(['comic/detail', 'id' => $item['book_id']]); ?>"><?= "[{$item['book_title']}]"; ?></a>
                    </div>
                    <div class="tile-content">
                         <em class="text-muted">阅至: </em><a class="tooltip tooltip-top" data-tooltip="<?= $item['item_name']; ?>" href="<?= Url::to(['comic/item', 'id' => $item['book_id'], 'itemId' => $item['item_id']]); ?>"><?= BookHelper::getBookItemName($item); ?></a>
                    </div>
                    <div class="tile-action">
                        <a class="history-delete text-muted hover" href="javascript:void(0);" data-href="<?= Url::to(['user/delete-history', 'id' => $item['id']]); ?>"><i class="icon-trash-o"></i></a>
                    </div>
                </div>
            <?php endforeach; ?>

            <?php else: ?>
                <h4 class="empty">您还没有阅读过哦</h4>
            <?php endif; ?>
        </div>
    </div>
</div>